<?php
namespace app\admin\controller;


use app\common\lib\Util;

class Live
{
    public function push()
    {
        // print_r( $_GET );
        if ( !$_GET ) {
            return Util::show( false, '发送消息不能为空' );
        }
        print_r( $_GET );
        $teams = [
            1 => [
                'name' => '马刺',
                'logo' => '/live/imgs/team1.png',
            ],
            4 => [
                'name' => '火箭',
                'logo' => '/live/imgs/team2.png',
            ],
        ];

        try {
            $data = [
                'type' => intval($_GET['type']),
                'title' => $teams[$_GET['team_id']]['name'] ?: '直播员',
                'logo' => $teams[$_GET['team_id']]['logo'] ?: '',
                'content' => $_GET['content'] ?: '',
                'image' => array_key_exists( 'image', $_GET ) ? $_GET['image'] : '',
            ];

            // 获取广播列表
            // todo 广播队列的维护
            $fdList = \app\common\lib\redis\Predis::getInstance()->smembers(config('redis.live_game_key'));
            print_r($fdList);


            foreach( $fdList as $fd ) {
                $_POST[ 'http_server' ]->push( $fd, json_encode( $data ) );
            }

        } catch (\Exception $e) {
            echo $e->getMessage();
        }

        // 获取连接的用户
        // 赛况的基本信息入库   2、数据组织好 push到直播页面
    }
}